package cn.chenxiejia;

import java.time.Duration;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: D4
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/10 17:32
 */
public class D4 {
    public static void main(String[] args) {
        //获取当前的时间,设置时区，默认使用系统时区
        LocalTime lt = LocalTime.now(ZoneId.of("GMT+8"));
        System.out.printf("%tT%n", lt);
        //设置时间
        LocalTime lt1 = LocalTime.of(23, 59, 59);
        System.out.println(lt1.getHour());
        System.out.println(lt1.getMinute());
        System.out.println(lt1.getSecond());
        System.out.println(lt1.getNano());
        //时间加减
        System.out.println(lt1.plusHours(1));
        System.out.println(lt1.minusMinutes(50L));
        //两个时间差
        //方式1
        System.out.println(lt.until(lt1, ChronoUnit.HOURS));
        System.out.println(lt.until(lt1, ChronoUnit.MINUTES));
        System.out.println(lt.until(lt1, ChronoUnit.SECONDS));
        //方式2
        System.out.println(Duration.between(lt, lt1).toMinutes());
        System.out.println(Duration.between(lt, lt1).toMillis());
        //方式3
        System.out.println(ChronoUnit.HOURS.between(lt, lt1));
        System.out.println(ChronoUnit.MINUTES.between(lt, lt1));

    }
}
